import client from './httpclient'
import type { ResponseModel } from './httpclient'

export enum AuthErrorCode {
  OK = 0,
  UserNotFound = 1000,
  UserAlreadyExists = 1001,
}

export interface AccountLoginReq {
  account_name: string
  password: string
}

export interface EmailLoginReq {
  email: string
  password: string
}

export interface LoginRsp {
  access_token: string
  refresh_token: string
}

export const login = (
  req: AccountLoginReq | EmailLoginReq,
): Promise<ResponseModel<LoginRsp, AuthErrorCode>> => {
  return client.post<LoginRsp>({
    url: '/auth/login',
    data: req,
  })
}
